#ifndef _OSM_CONVERTER_
#define _OSM_CONVERTER_

#include <vector>
#include <string>
#include <boost/unordered_map.hpp>
#include "polygon.h"
#include "MAP_OBJECT.h"
#include "DBMaster.h"


typedef std::vector<point_t> way_t;

struct ExtractedItem
{
	ExtractedItem();
	ExtractedItem(way_t const & way, std::string const & title, std::string const & type);

	way_t const & way() const;
	std::string const & title() const;
	bool is_area() const;
	mobj_type type() const;

private:
	way_t way_;
	std::string title_;
	std::string type_;
};


struct OsmConverter
{
	OsmConverter();
    OsmConverter(std::string const & file);
    
	ExtractedItem const & operator[] (size_t idx) const;
	size_t size() const;

private:
	typedef boost::uint32_t node_id_t;
    typedef boost::unordered_map<node_id_t, point_t> node_map_t;
	typedef std::vector<node_id_t> osm_way_t;
	
	node_map_t node_map_;

    osm_way_t current_way_;

    std::string goal_;
    boost::unordered_map<std::string, std::string> attributs_;
    bool way_started_;

	std::vector<ExtractedItem> items_;

    void parse(std::string const & file);

    friend void startTag(void * data, char const * el, char const ** attr);
    friend void endTag(void * data, char const * el);

    void processNode(char const ** attr);
    void processTag(char const ** attr);
    void processNd(char const ** attr);
    void endOfWay();

    std::string getType() const;

};

polygon_t get_polygon(way_t const & way, bool is_area);
DBMaster extractData(OsmConverter const & converter);


#endif 
